<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html:html>
<head>	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/sampleForm.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/me.css" />	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/help/help.css" />
	<title>บันทึกใบขอโอนสินค้า  (BCStkTransfer2, BCStkTransferSub2)</title>
	<script type='text/javascript' src='/ittl/dwr/interface/BCProjectService.js'></script>
	<script type='text/javascript' src='/ittl/dwr/interface/BCItemService.js'></script>
	<script type='text/javascript' src='/ittl/dwr/interface/BCItemUnitService.js'></script>
	<script type='text/javascript' src='/ittl/dwr/interface/BCStkTransfer2Service.js'></script>
	<!-- 
  	<script type='text/javascript' src='/ittl/dwr/interface/ItemLocationService.js'></script>
  	 -->
  	
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>

	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.bgiframe.min.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.ajaxQueue.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/thickbox-compressed.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.autocomplete.js' ></script>
	
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata2.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/codeOfBuyRequest.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata31.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartment.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartmentName.js' ></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/mainOLD.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/thickbox.css" />
 
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery.validate.js" ></script>
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery-1.4.2.min1.js" ></script>

<!-- start 
 
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" />
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/demos/demos.css" rel="stylesheet" />
	  	
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/external/jquery.bgiframe-2.1.1.js"></script>			
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.effects.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.autocomplete.js"></script>
			
-->
<!-- end -->

<!-- start add/remove  
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery-latest.pack.js'></script>	
-->	
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery.highlightFade.js'></script>
	<script type="text/javascript">
		
	var id = 1;	

	var idArray = new Array();
	idArray[0] = 1;
	idArray[1] = 0;
	idArray[2] = 0;
	idArray[3] = 0;
	//idArray[4] = 0;
	var max = false;
	
	function addFormField() {
		countId = document.getElementById("countId").value;
		//alert(countId);
		for(i=0;i<countId;i++) {
			idArray[i] = 1;
		}		
		max = true;
		for (i=0; i<idArray.length; i++) {
			if(idArray[i]==0) {
				max = false;
				idArray[i] = 1;
				id = i+1; 
				i = idArray.length;

				//alert(id);
				
				var newInput = "<tr id='r"+id+"'>"+
									"<td><a href='#' onClick='removeFormField(\"#r" + id + "\", \"#r"+id+id+"\", "+id+"); return false;'>"+
										"<img src=\"<%=request.getContextPath() %>/common/images/remove.png\" width='24' height='24' alt='Remove' /></a></td>"+
									"<td><input	type='text' name='itemCode' value='' size='12' "+ 
										     " onblur=\"getItem(document.getElementById('suggestCode"+id+id+"').value,"+id+")\" id='suggestCode"+id+id+"'> "+
								     	"</td><td><a href=\"#\" target=\"name\" onclick=\"modalWinItem('/ittl/stktransfer/stktransfer2.do?mode=popupItems&lineNumber="+id+"'); return false;\"><img src='../images/Find2.bmp'></a></td>"+
									
									"<td><input type='text' name='ittl_itemName' value='' maxlength='200' size='40' id='itemName"+id+"' >"+	
																						
									"</td><td>&nbsp;</td>"+														
									"<td align='center'>"+																																																													        
									"	<input type='text' name='unitName"+id+"' id='unitName"+id+"' onblur=\"getItemUnit(document.getElementById('unitName"+id+"').value,"+id+")\" style='width:50px'>"+
									"	<input type='hidden' name='unitCode' id='unitCode"+id+"' >"+										
									"	<input	type='hidden' name='price"+id+"' value='0' id='price"+id+"'>"+
									"	<input	type='hidden' name='amount"+id+"' value='0' id='amount"+id+"'>"+
									"</td><td><a href='#' target='name' onclick=\"modalWinItem2('/ittl/buyRequest/buyRequest.do?mode=unitCodeShow&lineNumber="+id+"',320); return false;\"><img src='../images/Find2.bmp'></a></td>"+
					
									"<td><input	type='text'	name='qty' value=''  size='5' id='qty"+id+"' ></td><td>&nbsp;</td>"+
									"<td><input	type='text'	name='myDescriptionSub' value='' id='myDescriptionSub"+id+"' ></td>"+
									"<td></td>"+						
								"</tr>"+
								"<tr id='r"+id+id+"'>"+
									"<td>&nbsp;</td>"+								
							  		"<td><input type='hidden' name='shortName"+id+"' value='' size='10' id='shortName"+id+"'>&nbsp;</td>"+
							  	    "<td>&nbsp;</td>"+
									"<td>"+
										"<input type='text' name='myDescription"+id+"' value='' maxlength='200' size='40' id='myDescription"+id+"'>"+					
									"</td>"+
									"<td>&nbsp;</td>"+										
									"<td colspan='2'><font color='red' size='1'><label id='error_unitName"+id+"'></label></font></td>"+
								
									"<td colspan='2'>&nbsp;</td>"+
									"<td>&nbsp;</td>"+								
								"</tr>"


				//alert(newInput);
				$("#inputs").append(newInput); 
				$('#r' + id).highlightFade({
					speed:2000
				});			
				$("#suggestCode"+id+"old").autocomplete(codes, {
					max:30,
					minChars: 0,
					autoFill: true,
					mustMatch: true,
					matchContains: false,
					scrollHeight: 200				
				});

				$("#suggestCode"+id+id+"old").autocomplete(itemsName, {
					minChars: 0,
					width: 400,
					max:50,
					mustMatch: true,
					matchContains: true,
					autoFill: false,
					formatItem: function(row, i, max) {
						return row.code + ": [" + row.name + "]";
					},
					formatMatch: function(row, i, max) {
						return row.code + ": [" + row.name + "]";
					},
					formatResult: function(row) {
						return row.code;
					}
				});
								
			}
		}
						
		if(max==true) {											 	
			alert("คุณสามารถเพิ่มข้อมูลได้สูงสุด 4 รายการ");
		}				
	}
	
	function removeFormField(rid,rid2, id) {

		var answer = confirm('ยืนยันการลบข้อมูล');
		if(answer) {		
			var count = 0;
			countId = document.getElementById("countId").value;
			//alert(id);
			for(i=0;i<countId;i++) {
				idArray[i] = 1;
			}		
			for (i=0; i<idArray.length; i++) {
				if(idArray[i]>0) {
					count++;
				}
			}		
			if(count>1) {
				$(rid).remove();
				$(rid2).remove();
				idArray[id-1] = 0;
				document.getElementById("countId").value = countId-1;
			}else {
				alert("กรุณาบันทึกข้อมูลอย่างน้อย 1 รายการ");
			}
		}		

	}
		
	</script>
<!-- end add/remove  -->

<style type="text/css">
#form1 label.error {
	font-size: 1.0em;
	color: red;
}
</style>
 	
<script language="JavaScript">
 
function compareBuga() {
	return "buga22";
}

$.validator.addMethod("buga", function(value) {
	return value == compareBuga();
}, 'Please enter "buga"!');

$(document).ready(function() {
	 
	//$("#datepicker").datepicker();
	
/* 
	$("#dialog-confirm").dialog({
		autoOpen: true,
		resizable: false,
		height:140,
		modal: true,
		buttons: {
			'Delete all items': function() {
				$(this).dialog('close');
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		}
	});

*/	
	
	$("#form1").validate({
		
			
		submitHandler: function() {
			alert("txt1="+document.getElementById("txt1").value);
			alert("submitted!22");
			//$('#dialog-confirm').dialog('open');
			form.submit();
		},
				
		rules: {
			txt1: "required",
			docDate: "required",
			iTTL_deptPay: "required",
			projectCode1: "required",
			itemCode1: "required",
			itemCode2: "required",
			itemCode3: "required",
			itemCode4: "required",
			itemCode5: "required",
			itemName1: "required",
			itemName2: "required",
			itemName3: "required",
			itemName4: "required",
			itemName5: "required",
			unitName1: "required",
			unitName2: "required",
			unitName3: "required",
			unitName4: "required",													
			shelfCode1: "required",
			shelfCode2: "required",
			shelfCode3: "required",
			shelfCode4: "required",
			shelfCode5: "required",		
			qty1: {
				required: 	true,
				number:		true
			},
			qty2: {
				required: 	true,
				number:		true
			},
			qty3: {
				required: 	true,
				number:		true
			},
			qty4: {
				required: 	true,
				number:		true
			},
			qty5: {
				required: 	true,
				number:		true
			}						
		},
		messages: {
			txt1: "*",
			docDate: "*",
			iTTL_deptPay: "*",
			projectCode: "*",
			itemCode1: "*",
			itemCode2: "*",				
			itemCode3: "*",
			itemCode4: "*",
			itemCode5: "*",
			itemName1: "*",
			itemName2: "*",
			itemName3: "*",
			itemName4: "*",
			itemName5: "*",
			shelfCode1: "*",
			shelfCode2: "*",
			shelfCode3: "*",
			shelfCode4: "*",
			shelfCode5: "*",
			unitName1: "*",
			unitName2: "*",
			unitName3: "*",
			unitName4: "*",									
			qty1: "*",
			qty2: "*",
			qty3: "*",
			qty4: "*",
			qty5: "*"	
		},

		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			//alert("errorPlacement");			
			if ( element.is(":radio") ) {
				alert("radio");
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ) {
				alert("checkbox");
				error.appendTo ( element.next() );
			}else {
				/*alert(element("#itemCode1"));
				if(element.is("#itemCode1")) {
					error.appendTo( "#qty1-error" );
				}else {
					error.appendTo( element.parent().next() );	
				}*/
				//error.insertAfter('#qty1-error');
				error.appendTo( element.parent().next() );
			}
		}		
	});
	

	$("#suggest1").focus().autocomplete(cities);
	
	$("#suggestProjectOld").autocomplete(projects, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});

	
	$("#departCode").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestDeptPay").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestCode1").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200				
	});
	
	$("#suggestCode2").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#suggestCode3").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#suggestCode4").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	$("#suggestCode5").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#suggest11").autocomplete(cities, {
		matchContains: true,
		minChars: 0
	});

    $("#itemName5").autocomplete(cities, { scroll: true } );

	$("#suggest4").autocomplete(emails, {
		minChars: 0,
		
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
		},
		formatMatch: function(row, i, max) {
			return row.name + " " + row.to;
		},
		formatResult: function(row) {
			return row.to;
		}
	});

	$("#division1OLD").autocomplete(departmentsName, {
		minChars: 0,
		mustMatch: true,
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatMatch: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatResult: function(row) {
			return row.name;
		}
	});	

	$("#suggestCode11old").autocomplete(itemsName, {
		minChars: 0,
		width: 400,
		max:50,
		mustMatch: true,
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatMatch: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatResult: function(row) {
			return row.code;
		}
	});
			
});

</script>  

<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var inputNo;
var itemName = "";
var code;
var itemName;
var whCode;
var shelfCode;
var shelfName;

function getItem(var1,x) {	
	inputNo = x;
	BCItemService.getItem( var1, loadinfo2 );	  
}

<!--  ส่วนที่ 3 -->
function loadinfo2(item)
{
	code 	  = item.code;
	if(code=="") {
		alert("ไม่พบ "+document.getElementById('suggestCode'+inputNo+inputNo).value + "  ในระบบ");
		dwr.util.setValue("itemCode"+inputNo, "");
	}else {
		itemName  = item.itemName;
		shortName = item.shortName;
		whCode 	  = "10";//item.whCode;
		shelfCode = "10";//item.shelfCode;
		shelfName = item.shelfName;
		unitCode = item.unitCode;
		unitName = item.unitName;
		ittl_row = item.ittl_row;
		ittl_shelf = item.ittl_shelf;
		
		dwr.util.setValue("itemCode"+inputNo, code);
		dwr.util.setValue("itemName"+inputNo, itemName);
		dwr.util.setValue("shortName"+inputNo, shortName);
		dwr.util.setValue("whCode"+inputNo, whCode);			
		dwr.util.setValue("unitCode"+inputNo, unitCode);
		dwr.util.setValue("unitName"+inputNo, unitName);			
		dwr.util.setValue("ittl_row"+inputNo, ittl_row);
		dwr.util.setValue("ittl_shelf"+inputNo, ittl_shelf);
	}											
}

function getData(var1,x) {	
	inputNo = x;
	ItemLocationService.getData( var1, loadinfo );	  
}

<!--  ส่วนที่ 3 -->
function loadinfo(data)
{
	code 	  = data.code;
	itemName  = data.name1;
	whCode 	  = data.whCode;
	shelfCode = data.shelfCode;
	shelfName = data.shelfName;
	unitCode = data.unitCode;
	unitName = data.unitName;

	ittl_row = data.ittl_row;
	ittl_shelf = data.ittl_shelf;
	
	dwr.util.setValue("itemCode"+inputNo, code);
	dwr.util.setValue("itemName"+inputNo, itemName);
	dwr.util.setValue("whCode"+inputNo, whCode);
	dwr.util.setValue("whCode1"+inputNo, whCode);
	dwr.util.setValue("unitCode"+inputNo, unitCode);
	dwr.util.setValue("unitName"+inputNo, unitName);
	//redirectN(0, document.getElementById('shCode1'));
			
	dwr.util.setValue("ittl_row"+inputNo, ittl_row);
	dwr.util.setValue("ittl_shelf"+inputNo, ittl_shelf);
			
}

function redirectN(x, tempN){
	
	var groupsN=5;//document.form1.shelfCode1.options.length
	var groupN=new Array(groupsN);
	for (i=0; i<groupsN; i++)
		groupN[i]=new Array();

	//var tempN=document.form1.shelfCode1;	
	//alert("tempN.options.length-1 = "+(tempN.options.length-1));
	for (m=tempN.options.length-1;m>=0;m--) {
		//alert(tempN.options[m]);
		tempN.options[m]=null;
	}
	
	if(shelfName != null) {
		for (i=0; i<shelfName.length; i++) {
			groupN[0][i]=new Option(shelfName[i], shelfCode[i]);
		}
					
		for (i=0;i<groupN[x].length;i++){
			text = groupN[x][i].value+":"+groupN[x][i].text;
			tempN.options[i]=new Option(text,groupN[x][i].value);
		}
		tempN.options[0].selected=true;
	}
}
</script>
<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getProject() {
	//alert("bcproject"+form1.projectCode.value); ใช้ใน ff ไม่ผ่าน			
	BCProjectService.getProject( document.getElementById("suggestProject").value, loadinfoProject );			  
}

<!--  ส่วนที่ 3 -->
function loadinfoProject(project){		
		
	if(project.name=="") {
		alert("หน่วยงบ :"+document.getElementById("suggestProject").value+"  ไม่มีในระบบ");
		document.getElementById("suggestProject").value ="";		
	}else {
		//dwr.util.setValue("projectCode", project.name);
		dwr.util.setValue("projectName", project.name);						
	}		     
}
</script>	
<script type="text/javascript">
var inputNo;
var code;
function getItemUnit(var1,x) {

	inputNo = x;
	BCItemUnitService.getItemUnit( var1, loadItemUnit );	  
}

<!--  ส่วนที่ 3 -->
function loadItemUnit(itemUnit)
{
	code 	  = itemUnit.code;
	//alert("code="+code);
	if(code=="" || code==null) {
		//alert("ไม่พบ "+document.getElementById('unitName'+inputNo).value + "  ในระบบ");
		dwr.util.setValue("unitName"+inputNo, "");
		document.getElementById('unitName'+inputNo).focus();
		document.getElementById('error_unitName'+inputNo).innerHTML="หน่วยไม่ถูกต้อง";
	}else {
		document.getElementById('error_unitName'+inputNo).innerHTML="";
		unitCode = itemUnit.code;
		unitName = itemUnit.name;
					
		dwr.util.setValue("unitCode"+inputNo, unitCode);
		dwr.util.setValue("unitName"+inputNo, unitName);			

	}											
}
</script>
<script type="text/javascript">
function alertValue() {
	alert(document.getElementById('htmlElementTest').value)
}
</script>

	<link type="text/css" href="<%= request.getContextPath() %>/css/datepicker/css/ui.all.css" rel="stylesheet" /> 
	
	<script type="text/javascript" src="<%= request.getContextPath() %>/css/datepicker/lib/jquery-ui-1.5.3.min.js"></script>
	

	<script type="text/javascript">
		$(document).ready(function(){
    			$("#docDate").datepicker({ altField: 'input#docDate', altFormat: 'yy-mm-dd' });
  		});
	</script>

<script type="text/javascript" >

function modalWinItem(aa) {
	var shelfCode = document.getElementById('fromShelf').value;
	
	if (window.showModalDialog) {				
		window.showModalDialog(aa+"&shelfCode="+shelfCode,"name","dialogTop:100px;dialogWidth:650px;dialogHeight:350px;center:yes");
	} else {		
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}
function modalWinItem2(link,width) {
	
	if (window.showModalDialog) {		
		window.showModalDialog(link,"name","dialogTop:200px;dialogLeft:650px;dialogWidth:"+width+"px;dialogHeight:500px;center:yes");
		//alert("true");
	} else {		
		window.open(link,'name','height=350,width=3000,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
		//alert("true2");
	}
}
function showKeyCode(c){
	// restrict input to a single character
	c = c.charAt(0);

	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++i){
	// convert i into a 2-digit hex string
		var h = i.toString(16);
		if (h.length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape(h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	alert(i);
}

function modalWinDocNo(aa) {
	if (window.showModalDialog) {
		var docDate = document.getElementById('docDate').value;// 
		//alert(docDate);	
		aa = aa + "?docDate="+docDate;	
		window.showModalDialog(aa,"name","dialogTop:100px;dialogWidth:360px;dialogHeight:200px;center:yes");
	} else {		
		alert("b");
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}

function findDocNo(fromShelfSelect) {
	var dateStr = dwr.util.getValue('docDate');
	BCStkTransfer2Service.getBCStkTransfer2(fromShelfSelect.value,dateStr, function(data){
		var docNoOld = dwr.util.getValue('docNoOld');
		var docNo = data.docNo;
		if(docNo.substring(0,5)==docNoOld.substring(0,5)) {
			dwr.util.setValue("docNo",docNoOld);
		} else {
			dwr.util.setValue("docNo",data.docNo);
		}
				
	});
}




</script>
</head>

<body><br />
<b id='docNew'></b>
<b id='docOld'></b>
<div id="wrapper">
	<!-- 
		<div id="header"><img src="images/kiuchilogo.png" width="305" height="80" /></div>
	 -->	 
	<div id="menu"><ul id="nav"></ul></div>

	<div id="content">
		<div id="menuNav"><a href='<%=request.getContextPath() %>/Login.do?mode=check'>หน้าหลัก</a> 
		>> คลังพัสดุ - ภายใน >> คลังสีเคมี PD >> บันทึกใบเสนอซื้อ(สีและเคมี) >> 1.บันทึกใบคำสั่งซื้อสีและเคมี  ${dept }  </div><br />
			
	<div style="background: #ffffff;">
	<p align="center" id="titleIssueType">บันทึกใบเสนอซื้อ(สี-เคมี)</p>
	<html:form action="/chemicalpo.do" styleId="form1"  >	 
					<input type="hidden" name="dept" value="${dept} " />
	       
	<div id="userPw01">
	<fieldset>
		<legend><b>ข้อมูลใบขอโอนสินค้า(สี-เคมี)</b></legend>
		   <center> 
		   <table border="1" >
			<tr>
				<td width="100"> เลขที่เอกสาร </td>
				<td>:</td>
				<td width="140">
					<input type="text" name="docNo" value="${s.docNo}" readonly="readonly" id="docNo" >
					<input type="hidden" name="docNoOld" value="${s.docNo}" id="docNoOld" >
				</td>
				<td >
				
				</td>				
			</tr>
			<tr>
				<td > วันที่เอกสาร</td>
				<td>:</td>
				<td ><input type="text" name="docDate" id="docDate" maxlength="10" value="${s.docDate}"></td>
				<td ></td>					
			</tr>						
			<tr>
				<td >ฝ่ายผู้เบิก </td>
				<td>:</td>
				<td ><input type="text" name="departCode" value="${s.departCode }" id="suggestDeptPay" ></td>
				<td >
					<a href="#" target="name" onclick="modalWinItem2('/ittl/buyRequest/buyRequest.do?mode=departmentShow&lineNumber=1',620); return false;">
						<img src="../images/Find2.bmp">
					</a>
				</td>	
				
			</tr>			 					
 			<tr>
 				<td valign="top">หมายเหตุ</td>
 				<td valign="top">:</td>
 				<td colspan="2"><input type="text" name="myDescription" value="${s.myDescription }" maxlength="200" size="50">
 					
 				</td>
 				
 			</tr>
 			 			 			 				 							
		</table>
		</center>
     </fieldset></div>
	
	
     
    <div id="items"> 
     <fieldset>
     	<legend><b>รายการ</b></legend>     	
     	     	
     	<p><a href="#" onClick="addFormField(); return false;">
     			<img src="<%=request.getContextPath() %>/common/images/add.png" width="24" height="24" alt="Add" />
     		</a>     			   
     	</p>
     	
     		<input type="hidden" id="id" value="0">
     	<center>	     		          	
		<table border="1" >
			<thead>
				<tr id="rHead">
				  <th width="24">&nbsp;</th>
				  <th width="100" align="center">รหัสสินค้า</th>
				  <th width="10">&nbsp;</th>
				  <th width="270" align="center">ชื่อรายการ</th>
				  <th width="10">&nbsp;</th>				
				  <th width="50"  align="center">หน่วย</th>
				  <th width="10">&nbsp;</th>
				  <th width="60"  align="center">จำนวน</th>
				  <th width="10">&nbsp;</th>
				  <th width="60"  align="center"></th>
				  			
				</tr>						
			</thead>
			
			<tbody id="inputs" >
			     		<input type="hidden" name="countId" id="countId" value="${countId }"></input>
			
				<logic:iterate name="itemResults" id="subId" indexId="id">
				<tr id="r${id+1 }">
					<td><a href='#' onClick='removeFormField("#r${id+1 }","#r${id+1 }${id+1 }",${id+1 }); return false;'>
						<img src="<%=request.getContextPath() %>/common/images/remove.png" width="24" height="24" alt="Remove" /></a>
					</td>								
				  	<td><input 	type="text" name="itemCode" value="${subId.itemCode }" size="12" 
				  				onblur="getItem(document.getElementById('suggestCode${id+1 }${id+1 }').value,${id+1 })" id="suggestCode${id+1 }${id+1 }" >
				  					  		
				  	</td>
				  	<td><a href="#" target="name" onclick="modalWinItem('/ittl/purchaseOrder/chemicalpo.do?mode=popupItems&lineNumber=${id+1 }'); return false;">
				  		<img src="../images/Find2.bmp"></a></td>
					<td><input 	type="text" name="ittl_itemName" value="${subId.itemName }" maxlength="200" size="40" id="itemName${id+1 }">											
					</td><td>&nbsp;</td>
										
					<td align="center">
						<input type="text" name="unitName${id+1 }" id="unitName${id+1 }" value="Kgs."
								onblur="getItemUnit(document.getElementById('unitName${id+1 }').value,${id+1 })" style="width:50px">					
						<input type="hidden" name="unitCode" id="unitCode${id+1 }" value="">						
						<input type="hidden" name="price${id+1 }" value="0" >
						<input type="hidden" name="amount${id+1 }" value="0" >						
					</td><td><a href="#" target="name" onclick="modalWinItem2('/ittl/buyRequest/buyRequest.do?mode=unitCodeShow&lineNumber=${id+1 }',320); return false;">
				  		<img src="../images/Find2.bmp"></a></td>
					<td><input	type="text"	name="qty" value=""  size="5" id="qty${id+1 }" ></td>
					<td>&nbsp;</td>
					<td><a href="#" target="name" onclick="modalWinItem2('/ittl/purchaseOrder/chemicalpo.do?mode=chemicalHistory&lineNumber=${id+1 }&itemCode=${subId.itemCode }&dept=${dept }',900); return false;">
				  		<img src="../images/Find2.bmp"></a></td>										
				</tr>
				<tr id="r${id+1 }${id+1 }">
					<td>&nbsp;</td>								
				  	<td>&nbsp;</td>
				  	<td>&nbsp;</td>
					<td>
					</td>
					<td>&nbsp;</td>										
					<td colspan="2"><font color="red" size="1"><label id="error_unitName${id+1 }"></label></font></td>
					
					<td colspan="2">&nbsp;</td>
					<td></td>								
				</tr>				
			 </logic:iterate>
			</tbody>
			<tfoot>

			</tfoot>						
		</table>
		</center><br></br>     	
		<font size='2'>หมายเหตุ : <font color="red">*</font> คือข้อมูลที่ต้องใส่</font>
     </fieldset>
 	</div>
 	
 	<table border="0" align="center" width="100%">
 		<tr>
 			<td align="center" ><html:submit property="mode" value="update" onclick="return confirm('ยืนยันการบันทึกข้อมูล?');"  /></td>
 			<td align="center" ><html:submit property="mode" value="delete" onclick="return confirm('ยืนยันการบันทึกข้อมูล?');"  /></td>
			<td align="center" >
</td> 			
 		</tr>
 	</table>    	    	    	
    </html:form>	
	</div>
	</div>
	</div> 
</body>

</html:html>